package sdk.org.apache.shiro.G2_使用.C03_登录和退出;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.authc.ExcessiveAttemptsException;
import org.apache.shiro.authc.ExpiredCredentialsException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.web.env.IniWebEnvironment;

import com.titan.core.utils.debug.Timer;

import sdk.org.apache.shiro.utils.ShiroUtils;

import org.apache.shiro.env.Environment;
import org.apache.shiro.env.DefaultEnvironment;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class Main {
    public static void main(String[] args) {
        Timer timer = Timer.$();
        try {
            ShiroUtils.init("shiro.ini");
            run(timer);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            timer.print("执行总用时");
            System.exit(0);
        }
    }
    private static void run(Timer timer) throws Exception {
        ShiroUtils.login("zhang", "123", true);
        
        // 断言用户已经登录
        Subject currentUser = SecurityUtils.getSubject();
        System.out.println("当前用户"+currentUser.getPrincipal()+"的登录状态："+currentUser.isAuthenticated());
        
        // 用户退出
        ShiroUtils.logout();
    }
}
